home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs53.d81 / 28may87s.pma / FAST8502.ASM < prev    next >
Assembly Source File  |  1979-12-31  |  18KB  |  922 lines

  1.  
  2.  
  3.     title    '8502 drivers        4 Mar 86'
  4.  
  5.     maclib    x6502
  6.  
  7.     maclib    z80
  8.  
  9.     maclib    cxequ
  10.  
  11. $-MACRO
  12. ;
  13. ;      COMMON EQUATES
  14. ;
  15. ; page 0 variables, from 0a to 8f are usable
  16. ;
  17. prtno        equ    0000Ah        ; 0Ah
  18. second$adr    equ    prtno+1        ; 0Bh
  19. DATCHN        equ    second$adr+1    ; 0Ch
  20. CMDCHN        equ    datchn+1    ; 0Dh
  21. DEVNO        equ    cmdchn+1    ; 0Eh
  22. adr$1        equ    devno+1        ; 0Fh
  23. temp$byte    equ    adr$1+2        ; 11h
  24. ;        equ    temp$byte+1    ; 12h
  25.  
  26. pal$nts        equ    00a03h        ; FF=PAL=50Hz 0=NTSC=60Hz
  27. serial        equ    00a1ch
  28. d2pra        equ    0dd00h        ; serial control port (clk and data)
  29. d1sdr        equ    0dc0ch        ; Fast serial data reg.
  30. d1icr        equ    0dc0dh        ; serial channel interrupt control reg
  31.  
  32. clkbit        equ    10h        ; d2pra clock bit mask
  33. ;
  34. ;    KERNAL EQUATES
  35. ;
  36. K$spin$spout    equ    0FF64h        ; C=0 spin  C=1 spout
  37.  
  38. K$setbnk    equ    0FF68h        ; set the logical bank # for open
  39.                     ;  disk commands
  40.                     ;I A=load and store bank # (C128 type bank)
  41.                     ;  X=file name bank #
  42.  
  43. K$readst    equ    0FFB7h        ; read status byte
  44.                     ;O A = status
  45.  
  46. K$setlfs    equ    0FFBAh        ; setup a logical file
  47.                     ;I A=logical file #
  48.                     ;  X=device # (0-31)
  49.                     ;  Y=seconday command (FF if nane)
  50.  
  51. K$setnam    equ    0FFBDh        ; set up file name for OPEN
  52.                     ;I A=name length
  53.                     ;  X=low byte pointer to name
  54.                     ;  Y=high byte pointer to name
  55.  
  56. K$open        equ    0FFC0h        ; open a logical file (after setlfs
  57.                     ; and setnam)
  58.                     ;O A = error # (1,2,4,5,6,240)
  59.  
  60. K$chkin        equ    0FFC6h        ; open a channel for input
  61.                     ;I X = logical file #
  62.                     ;O A = errors #(0,3,5,6)
  63.  
  64. K$chkout    equ    0FFC9h        ; open a channel for output
  65.                     ;I X = logical file #
  66.                     ;O A = error #(0,3,5,7)
  67.  
  68. K$clrchn    equ    0FFCCh        ; clears ALL I/O channel 
  69.  
  70. K$chrin        equ    0FFCFh        ; get a character from input channel
  71.                     ;O A=input character 
  72.  
  73. K$chrout    equ    0FFD2h        ; output a character to output channel
  74.                     ;I A =output char
  75.  
  76. ;GETIN        equ    0FFE4h
  77.  
  78. K$clall        equ    0FFE7h        ; close ALL open logical files
  79.  
  80. K$close        equ    0FFC3h        ; close a logical file
  81.                     ;I A = logical channel # to be closed
  82.                     ;O A = error #(0,240)
  83.  
  84. RESET        equ    0FFFCh
  85.  
  86.     PAGE
  87. ;
  88.     org    bios8502
  89. ;
  90. ; **** THIS IS THE COMMAND LOOP ****
  91. ;
  92. start:
  93.   if    use$fast
  94.     @ldx    sys$speed    ;-K  get desired system speed
  95.     @stx    vic$speed    ;-K  set system speed
  96.   endif
  97.     @ldx    -1,#        ;-K
  98.     @txs            ;-K set the stack to the top
  99.     @JSR    VICIO        ;-K  go find and do requested operation
  100. bios$exit:
  101.     @sei            ;?K  DISABLE INTERRUPTS
  102.     @ldx    3eh,#        ;?K  set up Z80 memory map as required
  103.     @stx    force$map    ;?K
  104.     @ldx    82h,#        ;-K
  105.     @stx    CIA1+int$ctrl    ;-K  turn on CIA timer B interrupts
  106.   if    use$fast
  107.     @ldx    0,#        ;-K  get value for 1 MHz mode (slow)
  108.     @stx    vic$speed    ;-K  set system speed
  109.   endif
  110.     @jmp    enable$z80+6    ;-K
  111.  
  112.     PAGE
  113. ;
  114. ;
  115. ;
  116. iotbl:
  117.     dw    sys$reset    ;-1 reset system (C128)
  118.     dw    initilize    ;0 initialize the 8502
  119.     dw    READ        ;1 Read a sector of data to sector buffer
  120.     dw    WRITE        ;2 Write a "     "   "   "    "      "
  121.     dw    readf        ;3 Set-up for fast read (154X only)
  122.     dw    writef        ;4 Set-up for fast write (154X only)
  123.     dw    dsktst        ;5 test for 154x and diskette type
  124.     dw    query$dsk    ;6 get disk characteristics
  125.     dw    PRINT        ;7 print data character
  126.     dw    FORMAT        ;8 format disk as 1541 disk
  127.     dw    user$fun    ;9 vector to user code (L=viccount,H=vicdata) 
  128.     dw    ram$dsk$rd    ;10 RAM disk read
  129.     dw    ram$dsk$wr    ;11 RAM disk write
  130.  
  131.  
  132. NUMCMD        equ    ($-IOTBL)/2    ; NUMBER OF COMMANDS
  133. iotbl$low    equ    low(iotbl)
  134.  
  135.  
  136. ;
  137. ;
  138. ;
  139. sys$reset:            ;**CMD ENTRY**
  140.     @jsr    en$kernal    ;-K
  141.     @JMP    (RESET)        ;+K
  142. ;
  143. ;
  144. ;
  145. user$fun:            ;**CMD ENTRY**
  146.     @jmp    (vic$count)    ;-K
  147.  
  148.     page
  149. ;
  150. ; **** IO COMMAND DISPATCH ROUTINE ****
  151. ;
  152. VICIO:
  153.     @lda    vic$cmd        ;-K  get the command
  154.     @cmp    NUMCMD,#    ;-K  is this a valid command
  155.     @bcs    bad$command    ;-K  no, exit without doing anything
  156.                 ;-K  yes, get vector to it
  157.     @cld            ;-K  clear to binary mode
  158.     @asl    a        ;-K  A=2*CMD (carry cleared)
  159.     @clc            ;-K
  160.     @adc    iotbl$low+2,#    ;-K  add to vector table start address
  161.     @sta    VICIO2+1    ;-K  modify the JMP instructions ind adr
  162. VICIO2:
  163.     @jmp    (IOTBL)        ;-K  this is the ind adr that
  164.                    ; is modified above
  165. ;
  166. ;
  167. ;
  168. input$byte:
  169.     @sei
  170.     @lda    d2pra
  171.     @eor    clk$bit,#
  172.     @sta    d2pra
  173. ;
  174.     @lda    8,#
  175. in$1:
  176.     @bit    d1icr
  177.     @beq    in$1
  178.     @lda    d1sdr
  179. bad$command:
  180.     @RTS            ;-K
  181.  
  182.     page
  183. ;
  184. ;    initialize the 8502
  185. ;
  186. initilize:            ;**CMD ENTRY**
  187.     @ldx    low(irqs),#        ;-K
  188.     @ldy    high(irqs),#        ;-K
  189.     @stx    314h            ;-K  IRQ vector
  190.     @sty    315h            ;-K
  191.     @stx    316h            ;-K  BRK vector
  192.     @sty    317h            ;-K
  193.     @stx    318h            ;-K  NMI vector
  194.     @sty    319h            ;-K
  195.  
  196.     @jsr    en$kernal        ;-K
  197.     @lda    0fffeh            ;+K
  198.     @sta    0fffeh            ;+K  write to RAM under ROM
  199.     @lda    0ffffh            ;+K
  200.     @sta    0ffffh            ;+K
  201.  
  202.     @lda    6,#            ;+K
  203.     @sta    CIA2+data$dir$b        ;+K setup user port for RS232
  204.  
  205.     @lda    pal$nts            ;+K -1=50Hz(PAL) 0=60Hz(NTSC)
  206.     @sta    sys$freq        ;+K
  207.     @jmp    K$clall            ;+K  close all open files
  208.  
  209.     PAGE
  210. ;
  211. ; **** DISK SECTOR READ ****
  212. ;
  213. READ:                ;**CMD ENTRY**
  214.     @JSR    set$drv        ;-K
  215.     @jsr    en$kernal    ;+K
  216.     @ldx    datchn        ;+K
  217.     @jsr    K$chkin        ;+K
  218.     @bcs    disk$changed    ;+K
  219.     @jsr    K$clrchn    ;+K  clear the input channel for now
  220.  
  221.     @LDA    '1',#        ;+K  read command
  222.     @JSR    setup        ;+K  send it
  223.     @JSR    CKINDT        ;+K
  224.     @LDX    0,#        ;+K
  225. ;
  226. READ1:
  227.     @JSR    K$chrin        ;+K  get a byte from the KERNAL
  228.     @STA    @BUFFER,X    ;+K  save it in the buffer
  229.     @INX            ;+K  advance the buffer pointer
  230.     @BNE    READ1        ;+K  loop back if not past buf end
  231.     @jmp    K$clrchn    ;+K  CLEAR CHANNEL
  232. ;
  233. ;
  234. disk$changed:
  235.     @lda    0bh,#        ;?K  disk changed error code
  236.     @sta    vic$data    ;?K
  237.     @jmp    en$K$open    ;?K
  238.  
  239.     page
  240. ;
  241. ; **** DISK SECTOR WRITE ****
  242. ;
  243. WRITE:                ;**CMD ENTRY**
  244.     @jsr    set$drv        ;-K
  245.     @jsr    ckotcm        ;-K
  246.     @LDY    setpnt$lng,#    ;+K
  247. ;
  248. WRITE0:
  249.     @LDA    SETPNT,X    ;+K
  250.     @JSR    K$chrout    ;+K
  251.     @INX            ;+K
  252.     @DEY            ;+K
  253.     @BNE    WRITE0        ;+K
  254.  
  255.     @JSR    K$clrchn    ;+K
  256.     @JSR    CKINCM        ;+K
  257.     @BNE    WRITE2        ;+K
  258.  
  259.     @JSR    K$clrchn    ;+K
  260.     @JSR    CKOTDT        ;+K
  261.     @LDX    0,#        ;+K
  262. ;
  263. WRITE1:
  264.         @sei             ;+K  disable interrupts
  265.     @ldy    3fh,#        ;+K  enable all RAM in bank 0
  266.     @sty    force$map    ;+K
  267.     @LDA    @BUFFER,X    ;-K
  268.     @ldy    0,#        ;-K  re-enable kernal
  269.     @sty    force$map    ;-K
  270.     @JSR    K$chrout    ;+K  write buffer character
  271.     @INX            ;+K
  272.     @BNE    WRITE1        ;+K  write all 256 bytes of buffer
  273.  
  274.     @JSR    K$clrchn    ;+K  clear the channel
  275.     @LDA    '2',#        ;+K  write command
  276.     @JMP    setup        ;+K
  277. ;
  278. WRITE2:
  279.     @lda    0ffh,#        ;+K
  280.     @sta    vic$data    ;+K  writes thru ROM to RAM
  281.     @jmp    opencm        ;+K
  282.  
  283.     page
  284. ;
  285. ;    Set-up for fast disk write
  286. ;
  287. writef:                ;**CMD ENTRY**
  288.     @lda    2,#        ;-K 2=read command
  289.     @skip2            ;-K
  290. ;
  291. ;    Set-up for fast disk read
  292. ;
  293. readf:                ;**CMD ENTRY**
  294.     @lda    0,#        ;-K 0=read command
  295.     @sta    f$cmd        ;-K
  296.     @lda    0,#        ;-K
  297.     @sta    vic$data    ;-K
  298.     @jsr    set$drv$f    ;-K
  299.     @ldy    f$cmd$lng,#    ;-K  command set above rd/wr
  300.     @jsr    send$fast    ;-K
  301.     @jmp    clk$hi        ;+K
  302.  
  303.     page
  304. ;
  305. ;    test the format of the disk return code to CP/M
  306. ;    telling the disk type. Also test for FAST disk drive.
  307. ;
  308. dsktst:                ;**CMD ENTRY**
  309.     @lda    vic$drv        ;-K
  310.     @eor    0ffh,#        ;-K
  311.     @and    fast        ;-K
  312.     @sta    fast        ;-K  clear fast indicator bit for current drive
  313.  
  314.     @jsr    set$and$open    ;-K  set drv close and reopen the channel
  315.  
  316.     @ldx    0,#        ;+K  delay to allow drive to reset status
  317. tst$delay:
  318.     @nop            ;+K
  319.     @nop            ;+K
  320.     @dex            ;+K
  321.     @bne    tst$delay    ;+K
  322.  
  323.     @ldy    inq$cmd$lng,#    ;+K
  324.     @ldx    inq$cmd,#    ;+K
  325.     @jsr    send$fast$cmd    ;+K
  326.  
  327.     @jsr    input$byte    ;+K
  328.     @sta    vic$data    ;+K
  329.     @jsr    clk$hi        ;+K
  330.     @sty    io$0        ;+K  2/24
  331.     @lda    vic$drv        ;-K
  332.     @ora    fast        ;-K  set current drive as fast
  333.     @sta    fast        ;-K
  334.     @rts            ;-K
  335.  
  336.     page
  337. ;
  338. ;
  339. ;
  340. query$dsk:                ;**CMD ENTRY**
  341.     @jsr    set$drv$f        ;-K  will query track set by user
  342.     @ldy    query$cmd$lng,#        ;-K  command length is 4
  343.     @ldx    query$cmd,#        ;-K
  344.     @jsr    send$fast$cmd        ;-K
  345.     @jsr    input$byte        ;+K
  346.     @sta    vic$data        ;+K
  347.     @bpl    clk$hi            ;+K  exit if not MFM
  348.     @and    0eh,#            ;+K  test for error
  349.     @bne    clk$hi            ;+K  exit if error
  350.     @jsr    input$byte        ;+K  read offset sectors status byte
  351.     @sta    @buffer            ;+K
  352.     @and    0eh,#            ;+K  test for error
  353.     @bne    clk$hi            ;+K  exit if error 
  354.     @tax                ;+K get a zero in X
  355.     @ldy    5,#            ;+K five info bytes are sent back
  356. query$loop:
  357.     @inx
  358.     @jsr    input$byte
  359.     @sta    @buffer,X
  360.     @dey
  361.     @bne    query$loop
  362.  
  363. clk$hi:
  364.     @lda    d2pra            ;+K set clock bit HIGH
  365.     @and    0ffh-clkbit,#
  366.     @sta    d2pra
  367.     @rts
  368.  
  369.     PAGE
  370. ;
  371. ; **** PRINTER OUTPUT ****
  372. ;
  373. ;    this routine will support two printers
  374. ;    the device number is passed in vic$drv (4,5)
  375. ;    secondary address in vic$trk
  376. ;    the logical file number is equal to the device #
  377. ;    if VIC$count=0 then output character in VIC$data
  378. ;    if VIC$count<>0 then output characters pointered to by @buffer
  379. ;
  380. PRINT:                ;**CMD ENTRY**
  381.     @lda    vic$drv        ;-K
  382.     @sta    prtno        ;-K
  383.     @lda    vic$trk        ;-K
  384. ;;    @sta    second$adr    ;-K  this line should be deleted and one
  385.     @cmp    second$adr    ;-K  ..below used.
  386.     @sta    second$adr    ;-K  save secondary adr
  387.     @bne    reopen$prt    ;-K
  388.  
  389.     @jsr    en$kernal    ;-K
  390. print$cont:
  391.     @ldx    prtno        ;+K
  392.     @JSR    K$chkout    ;+K
  393.     @BCS    PERR0        ;+K  PRINT ERROR IF CARRY SET
  394.  
  395.     @sty    io$0        ;+K  2/24
  396.     @ldx    vic$count    ;-K  
  397.     @bne    print$buffer    ;-K
  398.     @LDA    vic$data    ;-K  GET CHARACTER
  399.     @sta    io$0        ;-K
  400.     @JSR    K$chrout    ;+K  AND PRINT IT
  401.     @JMP    K$clrchn    ;+K  CLEAR CHANNEL
  402.  
  403. print$buffer:
  404.     @stx    temp$byte    ;-K
  405.     @lda    @buffer        ;-K
  406.     @sta    adr$1        ;-K
  407.     @lda    @buffer+1    ;-K
  408.     @sta    adr$1+1        ;-K
  409.     @ldy    0,#        ;-K
  410.     @ldx    0,#        ;-K
  411.  
  412. print$buf$loop:
  413.     @sta    bank$0        ;?K    enable RAM bank 0 (no I/O)
  414.     @lda    (adr$1),y    ;rK
  415.     @stx    force$map    ;rK
  416.     @jsr    K$chrout    ;+K
  417.     @iny            ;+K
  418.     @dec    temp$byte    ;+K
  419.     @bne    print$buf$loop    ;+K
  420.     @jmp    K$clrchn    ;+K
  421.  
  422. ;
  423. ;
  424. PERR0:
  425.     @CMP    3,#        ;+K  FILE NOT OPEN?
  426.     @BNE    PERR1        ;+K  BRANCH IF NO
  427. reopen$prt:
  428.     @JSR    OPNPRT        ;?K  OPEN PRINTER CHANNEL
  429.     @BCC    print$cont    ;+K  IF CARRY CLEAR, OK TO PRINT
  430. PERR1:    @LDA    255,#        ;+K  NO DEVICE PRESENT
  431.     @STA    vic$data    ;+K  FLAG BAD ATTEMPT writes to ram under ROM
  432. PRTST:    @RTS            ;+K
  433.  
  434.     PAGE
  435. ;
  436. ; **** FORMAT DISK ROUTINE ****
  437. ;
  438. FORMAT:                ;**CMD ENTRY**
  439.     @jsr    set$drv$num    ;-K
  440.     @lda    fast        ;-K
  441.     @and    vicdrv        ;-K
  442.     @bne    format$fast    ;-K
  443.  
  444.     @JSR    CKOTCM        ;-K  returns X=0
  445.     @LDY    fmtcmd$lng,#    ;+K
  446. FMT1:    @LDA    FMTCMD,X    ;+K
  447.     @JSR    K$chrout    ;+K
  448.     @INX            ;+K
  449.     @DEY            ;+K
  450.     @BNE    FMT1        ;+K
  451.     @JSR    K$clrchn    ;+K
  452. fmt2:    @JSR    CKINCM        ;+K check for errors
  453.     @BEQ    setup3        ;+K no errors, return good status
  454.     @BNE    setup5        ;+K error return error status
  455.  
  456. format$fast:
  457.     @ldx    @buffer        ;-K get command length
  458. fast$F:                ;-K
  459.     @lda    @buffer+1-1,x    ;-K
  460.     @sta    F$cmd-1,x    ;-K
  461.     @dex            ;-K transfer command tail from buffer+1
  462.     @bne    fast$F
  463.     @ldy    @buffer        ;-K
  464.     @iny            ;-K
  465.     @iny            ;-K  count is tail length plus 2
  466.     @ldx    F$cmd        ;-K
  467.     @jsr    send$fast$cmd    ;-K
  468.     @jmp    fmt2        ;+K
  469.  
  470.     PAGE
  471. ;
  472. ;
  473. ;
  474. ram$dsk$rd:            ; RAM disk read
  475.     @ldx    81h,#            ;-K
  476.     @skip$2                ;-K
  477. ;
  478. ;
  479. ;
  480. ram$dsk$wr:            ; RAM disk write
  481.     @ldx    80h,#            ;-K
  482.   if    use$fast
  483.     @lda    0,#            ;-K  0=slow (1 MHz)
  484.     @sta    vic$speed        ;-K  set to slow mode
  485.   endif
  486.     @lda    3Fh,#
  487.     @stx    RM$command        ;-K  give command to RAM DISK
  488.      @sta    force$map        ;    remove I/O area
  489.     @rts                ;-K
  490.  
  491.  
  492.     PAGE
  493. ;
  494. ;
  495. ;
  496. setup:
  497.     @STA    DSKCMD+1    ;?K
  498.     @LDA    2,#        ;?K  RETRY COUNT
  499.     @STA    vic$data    ;?K  writes to RAM under ROM
  500.  
  501.     @JSR    CKOTCM        ;?K  returns X=0
  502.     @LDY    dskcmd$lng,#    ;+K
  503. setup2:
  504.     @LDA    DSKCMD,X    ;+K
  505.     @JSR    K$chrout    ;+K
  506.     @INX            ;+K
  507.     @DEY            ;+K
  508.     @BNE    setup2        ;+K
  509.  
  510.     @JSR    K$clrchn    ;+K
  511.     @JSR    CKINCM        ;+K
  512.     @BEQ    setup3        ;+K
  513.  
  514.     @sty    io$0        ;+K  2/24
  515.     @DEC    vic$data    ;-K
  516.     @BEQ    setup5        ;-K
  517.  
  518.     @jmp    disk$changed    ;-k
  519. ;
  520. ;
  521. setup5:
  522.     @LDA    0dh,#        ;?K  normal read/write error flag
  523.     @skip2            ;?K  ALWAYS
  524. ;
  525. ;
  526. ;
  527. setup3:
  528.     @lda    0,#        ;?K  get data good flag
  529. setup4:
  530.     @STA    vic$data    ;?K  writes to RAM under ROM    
  531.     @jsr    en$kernal    ;?K
  532.     @JMP    K$clrchn    ;+K
  533.  
  534.     page
  535. ;
  536. ;
  537. ;
  538. send$fast$cmd:
  539.     @jsr    set$cmd        ;?K  unit # must have been set already
  540. send$fast:
  541.     @ldx    0,#        ;?K
  542.     @stx    force$map    ;?K  enable the kernal
  543.     @ldx    cmdchn        ;+K
  544.     @jsr    K$chkout    ;+K
  545.     @bcs    chan$error    ;+K
  546.     @ldx    0,#        ;+K
  547. sendf:
  548.     @lda    f$cmd$buf,x    ;+K
  549.     @jsr    K$chrout    ;+K
  550.     @inx            ;+K
  551.     @dey            ;+K
  552.     @bne    sendf        ;+K
  553.     @jsr    K$clrchn    ;+K
  554.     @bit    serial        ;+K
  555.     @bvc    not$fast    ;+K
  556.     @bit    d1icr        ;+K  clear interrupts from chip
  557.     @rts            ;+K
  558.  
  559. chan$error:
  560.     @lda    0dh,#        ;+K  get error code
  561.     @skip2            ;+K
  562. not$fast:
  563.     @lda    0ch,#        ;+K  get error code
  564.     @sta    vic$data    ;+K
  565.     @jsr    clk$hi        ;+K
  566.     @jmp    bios$exit    ;+K
  567. ;
  568. ;
  569. ;
  570. set$cmd:
  571.     @lda    dskcmd+5    ;?K check lsb of unit #
  572.     @ror    a        ;?K get lsb to carry bit
  573.     @bcc    unit$0        ;?K
  574.     @inx            ;?K  make command for unit 1
  575. unit$0:
  576.     @stx    F$cmd        ;?K
  577.     @rts
  578.  
  579.     page
  580. ;
  581. ;    ........not tested........
  582. ;
  583. ;rd$buff:
  584. ;    @sei            ; disable interrupts
  585. ;    @lda    vic$data
  586. ;    @sta    adr$1+1        ; save hi part of address
  587. ;    @lda    0,#
  588. ;    @sta    adr$1        ; save low part of address
  589. ;    @tax            ; get a zero for both indexes
  590. ;    @tay
  591. ;
  592. ;rd$buf$1:
  593. ;    @lda    (adr$1),y    
  594. ;    @sta    @buffer,x
  595. ;    @inx
  596. ;    @iny
  597. ;    @bne    rd$buf$1
  598. ;    @rts
  599.  
  600.     PAGE
  601. ;
  602. ;
  603. ;
  604. set$drv:
  605.     @lda    vic$trk        ;-K
  606.     @jsr    binasc        ;-K
  607.     @stx    dskcmd+7    ;-K
  608.     @sta    dskcmd+8    ;-K
  609.  
  610.     @lda    vic$sect    ;-K
  611.     @bmi    no$side$1    ;-K
  612.     @jsr    binasc        ;-K
  613.     @stx    dskcmd+10    ;-K
  614.     @sta    dskcmd+11    ;-K
  615.     @jmp    set$drv$num    ;-K
  616.  
  617. no$side$1:
  618.     @lda    04h,#        ;-K
  619.     @sta    vic$data    ;-K
  620.     @jmp    bios$exit    ;-K
  621.  
  622. ;
  623. ;
  624. ;
  625. set$drv$f:
  626.     @lda    vic$count    ;-K
  627.     @sta    f$rd$count    ;-K
  628.  
  629.     @lda    vic$trk        ;-K
  630.     @sta    f$rd$trk
  631.  
  632.     @lda    vic$sect    ;-K
  633.     @bpl    side$0        ;-K
  634.     @tax            ;-K
  635.     @lda    f$cmd        ;-K
  636.     @ora    10h,#        ;-K
  637.     @sta    f$cmd        ;-K
  638.     @txa            ;-K
  639.     @and    7fh,#        ;-K
  640. side$0:
  641.     @sta    f$rd$sect    ;-K
  642.  
  643.     page
  644. ;
  645. ;         VIC$DRV               dev,dat,cmd
  646. ;        00000001    device  #8-0     8,11,15
  647. ;        00000010    device  #9-0     9,12,16
  648. ;        00000100    device #10-0    10,13,17
  649. ;        00001000    device #11-0    11,14,18
  650. ;        10000001    device  #8-1     8,11,15
  651. ;        10000010    device    #9-1     9,12,16
  652. ;        10000100    device #10-1    10,13,17
  653. ;        10001000    device #11-1    11,14,18
  654. ;
  655. set$drv$num:
  656.     @ldy    8-1,#        ;-K start as drive 8
  657.     @ldx    '0',#        ;-K ..unit 0
  658.     @lda    vic$drv        ;-K get requested drv#
  659.     @bpl    unit$nu$0
  660.     @inx            ;-K make unit 1
  661. unit$nu$0:
  662.     @iny            ;-K add one to the drive #
  663.     @lsr    a        ;-K is drive number correct?
  664.     @bcc    unit$nu$0    ;-K no, loop back
  665.  
  666.     @stx    dskcmd+5    ;-K save unit# to disk cmd string
  667.     @stx    fmtcmd+1    ;-K save unit# to format cmd string
  668.     @txa
  669.     @ror    a        ;-K get lsb to carry bit
  670.     @lda    F$cmd
  671.     @and    0feh,#
  672.     @adc    0,#        ; set the lsb if carry set (carry cleared)
  673.     @sta    F$cmd
  674.     @tya             ;-K get device # to A
  675.     @sta    devno        ;-K save device #
  676.     @adc    3,#        ;-K make the data chan# (carry cleared above)
  677.     @sta    datchn        ;-K save data chan#
  678.     @adc    4,#        ;-K make the cmd chan#
  679.     @sta    cmdchn        ;-K save cmd chan#
  680.     @lda    serial        ;-K
  681.     @and    0bfh,#        ;-K
  682.     @sta    serial        ;-K  clear the fast serial indicator
  683.     @rts            ;-K
  684.  
  685.     page
  686.  
  687. ;
  688. ; **** CONVERT BINARY TO ASCII ****
  689. ;
  690. BINASC:
  691.     @CLD            ;?K
  692.     @LDX    '0',#        ;?K
  693.     @SEC            ;?K
  694.  
  695. BA0:
  696.     @SBC    10,#        ;?K
  697.     @BCC    BA1        ;?K
  698.  
  699.     @INX            ;?K
  700.     @BCS    BA0        ;?K
  701.  
  702. BA1:
  703.     @ADC    3Ah,#        ;?K
  704.     @RTS            ;?K
  705.  
  706.     PAGE
  707. ;
  708. ; **** OPEN DISK COMMAND CHANNEL ****
  709. ;
  710. set$and$open:
  711.     @jsr    set$drv$num    ;-K
  712. en$K$open:
  713.     @jsr    en$kernal    ;-K
  714. opencm:
  715.     @LDA    CMDCHN        ;+K
  716.     @clc            ;+K  clear the carry to force true closing 
  717.     @JSR    K$close        ;+K
  718.  
  719.     @LDA    CMDCHN        ;+K
  720.     @LDX    DEVNO        ;+K
  721.     @LDY    15,#        ;+K
  722.     @JSR    K$setlfs    ;+K
  723.  
  724.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  725.     @sta    F$stat        ;+K  write status byte value = 0
  726.     @tax            ;+K  file name bank (C128 type bank#)
  727.     @jsr    K$setbnk    ;+K
  728.  
  729.     @ldx    write$stat,#    ;+K
  730.     @jsr    set$cmd        ;+K
  731.  
  732.     @lda    4,#        ;+K write status command lenght
  733.     @ldx    low(f$cmd$buf),#    ;+K
  734.     @ldy    high(f$cmd$buf),#    ;+K
  735.     @JSR    K$setnam        ;+K
  736.  
  737.     @JSR    K$open        ;+K
  738.     @bcs    misdsk
  739.  
  740.     @JSR    K$readst
  741.     @ROL    A        ;+K  GET MSB TO CARRY
  742.     @BCS    MISDSK        ;+K  DEVICE MISSING IF CARRY SET
  743.  
  744.     @bit    serial        ;+K  test for fast device
  745.     @bvs    no$dt$open    ;+K  do not open data channel if fast
  746. ;
  747. ; **** OPEN DISK DATA CHANNEL ****
  748. ;
  749. OPENDT:
  750.     @LDA    DATCHN        ;+K
  751.     @clc            ;+K  forces true closing of channel
  752.     @JSR    K$close        ;+K
  753.     @LDA    DATCHN        ;+K
  754.     @LDX    DEVNO        ;+K
  755.     @LDY    8,#        ;+K
  756.     @JSR    K$setlfs    ;+K
  757.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  758.     @tax            ;+K  file name bank (C128 type bank#)
  759.     @jsr    K$setbnk    ;+K
  760.     @LDA    1,#        ;+K
  761.     @LDX    low(POUND),#    ;+K
  762.     @LDY    high(POUND),#    ;+K
  763.     @JSR    K$setnam    ;+K
  764.     @jsr    K$open        ;+K
  765.     @bcs    misdsk
  766. no$dt$open:
  767.     @rts
  768.  
  769.     page
  770. ;
  771. ;
  772. ;  * DEVICE MISSING, CLEAN UP ERROR *
  773. ;
  774. MISDSK:
  775.     @LDA    0fh,#        ;+K  SET ERROR CODE for missing drive
  776.     @STA    vic$data    ;+K  writes to RAM under ROM
  777.     @LDA    CMDCHN        ;+K  K$close CHANNEL
  778.     @clc            ;+K  force true closing of channel
  779.     @JSR    K$close        ;+K
  780.     @JMP    bios$exit    ;+K
  781.  
  782.     PAGE
  783. ;
  784. ; **** SELF CORRECTING CHECK IO ROUTINES ****
  785. ;
  786. CKICM:
  787.     @JSR    OPENCM        ;+K
  788.  
  789. CKINCM:
  790.     @LDX    CMDCHN        ;+K
  791.     @JSR    K$chkin        ;+K
  792.     @BCS    CKICM        ;+K
  793.  
  794.     @JSR    K$chrin        ;+K
  795.     @CMP    '0',#        ;+K
  796.     @RTS            ;+K
  797. ;
  798. ;
  799. ;
  800. CKIDT:
  801.     @JSR    OPENDT        ;+K
  802. CKINDT:
  803.     @LDX    DATCHN        ;+K
  804.     @JSR    K$chkin        ;+K
  805.     @BCS    CKIDT        ;+K
  806.  
  807.     @RTS            ;+K
  808. ;
  809. ;
  810. ;
  811. CKODT:
  812.     @JSR    OPENDT        ;+K
  813. CKOTDT:
  814.     @LDX    DATCHN        ;+K
  815.     @JSR    K$chkout    ;+K
  816.     @BCS    CKODT        ;+K
  817.  
  818.     @RTS            ;+K
  819. ;
  820. ;
  821. ;
  822. CKOCM:
  823.     @jsr    OPENCM        ;+K
  824. CKOTCM:
  825.     @jsr    en$kernal    ;?K
  826.     @LDX    CMDCHN        ;+K
  827.     @JSR    K$chkout    ;+K
  828.     @BCS    CKOCM        ;+K
  829.  
  830.     @LDX    0,#        ;+K
  831.     @RTS            ;+K
  832.  
  833.     PAGE
  834. ;
  835. ; **** OPEN PRINTER CHANNEL ****
  836. ;
  837. opnprt:
  838.     @jsr    en$kernal    ;-K
  839.     @lda    prtno        ;+K
  840.     @clc            ;+K
  841.     @JSR    K$close        ;+K
  842.  
  843.     @lda    prtno        ;+K
  844.     @TAX            ;+K  LDX #4 (or #5)
  845.     @ldy    second$adr    ;+K secondary adr passed in vic$trk (normaly=7)
  846.     @JSR    K$setlfs    ;+K
  847.     @LDA    0,#        ;+K
  848.     @JSR    K$setnam    ;+K
  849.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  850.     @tax            ;+K  file name bank (C128 type bank#)
  851.     @jsr    K$setbnk    ;+K
  852.     @JMP    K$open        ;+K
  853.  
  854.     page
  855. ;
  856. ;    handle all interrupts in BIOS 8502 (throw them away)
  857. ;
  858. irqs:
  859.     @lda    CIA$1+int$ctrl
  860.     @lda    CIA$2+int$ctrl
  861.     @lda    0fh,#
  862.     @sta    VIC+25
  863.  
  864.     @pla
  865.     @sta    force$map
  866.     @pla
  867.     @tay
  868.     @pla
  869.     @tax
  870.     @pla
  871.     @rti
  872.  
  873. ;
  874. ;
  875. ;
  876. en$kernal:
  877.     @ldy    0,#        ;?K
  878.     @sty    force$map    ;?K
  879.     @rts            ;+K
  880.  
  881.     page
  882. ;
  883. ;
  884. ;
  885. DSKCMD:        db    'U1:8 0 tt ss',CR
  886. dskcmd$lng    equ    $-dskcmd
  887.  
  888. POUND:        db    '#'
  889.  
  890. FMTCMD:        db    'N0:CP/M DISK,65',CR
  891. fmtcmd$lng    equ     $-FMTCMD
  892.  
  893. SETPNT:        db    'B-P 8 0',CR
  894. setpnt$lng    equ    $-setpnt
  895. ;
  896. ;    fast command buffer
  897. ;
  898. f$cmd$buf:    db    'U0'    ; not set
  899. f$cmd:        db    0    ; byte 3
  900. F$stat:
  901. f$rd$trk:    db    1    ; byte 4
  902. f$rd$sect:    db    0    ; byte 5
  903. f$rd$count:    db    1    ; byte 6
  904.         db    0    ; byte 7
  905.         db    0    ; byte 8
  906.         db    0    ; byte 9
  907.         db    0    ; byte 10
  908.         db    0    ; byte 11
  909.  
  910. f$cmd$lng    equ    6        ; U0+cmd+track+sector+#sectors
  911.  
  912. write$stat    equ    01001100b
  913. write$stat$lng    equ    4        ; U0+cmd+(status to write)
  914.  
  915. inq$cmd:    equ    00000100b
  916. inq$cmd$lng    equ    3        ; U0+cmd
  917.  
  918. query$cmd:    equ    10001010b
  919. query$cmd$lng    equ    4        ; U0+cmd+(track offset)
  920.  
  921.  
  922.